package com.baosight.sczx.common.zm.cInterface.cs;

import java.util.HashMap;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.spring.SpringApplicationContext;
import com.baosight.iplat4j.dao.Dao;
import com.baosight.sczx.common.zm.basetools.TablePk;

/**
 * iH数据源
 * <p>Title: DatasourceIhistory.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 严洪浩
 * @version 1.0
 * <pre>Histroy:
 *          2011-6-9 上午05:34:12  严洪浩  Create
 *</pre>
 */
public class DatasourceIhistory {
	
	private static Dao dao = (Dao)SpringApplicationContext.getBean("dao");
	
	/**
	 * 变量新增时新增
	 * <p>Function: insert</p>
	 * <p>Description: </p>
	 * <p>return value:EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-9上午06:02:07 严洪浩
	 * </p>
	 *
	 */
	public static EiInfo insert(EiInfo inInfo) {
		String zbid = inInfo.getBlock(EiConstant.resultBlock).getCellStr(0, "fdKeyId");
		String fdKeyId = TablePk.getInstance().getNextValue("T_CI_ICVDATASOURCE");
		
		Map<String, String> _args = new HashMap<String, String>();
		_args.put("fdKeyId", fdKeyId);
		_args.put("fdVariableId", zbid);
		_args.put("fdNo", inInfo.getBlock(EiConstant.resultBlock).getCellStr(0, "fdTagNo"));
		
		dao.insert("ZMCSDatasourceIhistory.insert", _args);
		
		return inInfo;
	}
	
	/**
	 * 变量删除
	 * <p>Function: delete</p>
	 * <p>Description: </p>
	 * <p>return value:EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-9上午06:10:06 严洪浩
	 * </p>
	 *
	 */
	public static EiInfo delete(EiInfo inInfo) {
		String zbid = inInfo.getBlock(EiConstant.resultBlock).getCellStr(0, "fdKeyId");
		Map<String, String> _args = new HashMap<String, String>();
		_args.put("fdVariableId", zbid);
		
		try {
			dao.delete("ZMCSDatasourceIhistory.delete", _args);
		}
		catch(Exception e) {
			inInfo.setStatus(-1);
			inInfo.setMsg("iHistory变量表删除失败!");
		}
		
		return inInfo;
	}
	
	/**
	 * 变量修改
	 * <p>Function: update</p>
	 * <p>Description: </p>
	 * <p>return value:EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-9上午06:21:17 严洪浩
	 * </p>
	 *
	 */
	public static EiInfo update(EiInfo inInfo){
		String zbid = inInfo.getBlock(EiConstant.resultBlock).getCellStr(0, "fdKeyId");//主表ID
		String fdKeyId = inInfo.getBlock(EiConstant.resultBlock).getCellStr(0, "fdIHKeyId");//从表ID
		
		Map<String, String> _args = new HashMap<String, String>();
		_args.put("fdKeyId", fdKeyId);
		_args.put("fdVariableId", zbid);
		_args.put("fdNo", inInfo.getBlock(EiConstant.resultBlock).getCellStr(0, "fdTagNo"));
		
		try {
			dao.update("ZMCSDatasourceIhistory.update", _args);
		}
		catch(Exception e) {
			inInfo.setStatus(-1);
			inInfo.setMsg("iHistory变量表修改失败!");
		}
		
		return inInfo;
	}
}
